﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <!-- Resource dictionary entries should be defined here. -->
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Colors.xaml"/>
        <ResourceDictionary Source="ScrollBarStyle.xaml"/>
        <ResourceDictionary Source="ListViewItemStyle.xaml"/>
        <ResourceDictionary Source="ScrollViewerStyle.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <Style x:Key="{x:Static GridView.GridViewScrollViewerStyleKey}" TargetType="ScrollViewer">
        <Setter Property="Template" Value="{DynamicResource GridView.GridViewScrollViewerTemplate}"/>
    </Style>

    <Style x:Key="{x:Type GridViewColumnHeader}"
       TargetType="GridViewColumnHeader">
        <Setter Property="HorizontalContentAlignment" Value="Center" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="Foreground">
            <Setter.Value>
                <SolidColorBrush Color="{DynamicResource Application_ListViewHeader_Foreground}" />
            </Setter.Value>
        </Setter>
        <Setter Property="Template" Value="{DynamicResource GridViewColumnHeaderTemplate}"/>
        <Style.Triggers>
            <Trigger Property="Role" Value="Floating">
                <Setter Property="Opacity" Value="0.7" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="GridViewColumnHeader">
                            <Canvas Name="PART_FloatingHeaderCanvas">
                                <Rectangle Fill="#60000000" Width="{TemplateBinding ActualWidth}" Height="{TemplateBinding ActualHeight}" />
                            </Canvas>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Trigger>
            <Trigger Property="Role" Value="Padding">
                <Setter Property="Template" Value="{DynamicResource PaddingGridViewColumnHeaderTemplate}"/>
            </Trigger>
        </Style.Triggers>
    </Style>

    <Style TargetType="ListView">
        <Setter Property="SnapsToDevicePixels" Value="true" />
        <Setter Property="OverridesDefaultStyle" Value="true" />
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
        <Setter Property="ScrollViewer.CanContentScroll" Value="true" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="Template" Value="{DynamicResource ListViewTemplate}"/>
    </Style>

    <ControlTemplate x:Key="GridView.GridViewScrollViewerTemplate" TargetType="ScrollViewer">
        <Grid Background="{TemplateBinding Background}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <DockPanel Margin="{TemplateBinding Padding}">
                <ScrollViewer DockPanel.Dock="Top" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" Focusable="false">
                    <GridViewHeaderRowPresenter Margin="2,0,2,0" Columns="{Binding Path=TemplatedParent.View.Columns, RelativeSource={RelativeSource TemplatedParent}}"
                                                ColumnHeaderContainerStyle="{Binding  Path=TemplatedParent.View.ColumnHeaderContainerStyle, RelativeSource={RelativeSource TemplatedParent}}"
                                                ColumnHeaderTemplate="{Binding Path=TemplatedParent.View.ColumnHeaderTemplate, RelativeSource={RelativeSource TemplatedParent}}"
                                                ColumnHeaderTemplateSelector="{Binding Path=TemplatedParent.View.ColumnHeaderTemplateSelector, RelativeSource={RelativeSource TemplatedParent}}"
                                                AllowsColumnReorder="{Binding Path=TemplatedParent.View.AllowsColumnReorder, RelativeSource={RelativeSource TemplatedParent}}"
                                                ColumnHeaderContextMenu="{Binding Path=TemplatedParent.View.ColumnHeaderContextMenu, RelativeSource={RelativeSource TemplatedParent}}"
                                                ColumnHeaderToolTip="{Binding Path=TemplatedParent.View.ColumnHeaderToolTip, RelativeSource={RelativeSource TemplatedParent}}"
                                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                </ScrollViewer>
                <ScrollContentPresenter Name="PART_ScrollContentPresenter" KeyboardNavigation.DirectionalNavigation="Local" CanContentScroll="True" CanHorizontallyScroll="False" CanVerticallyScroll="False" />
            </DockPanel>

            <ScrollBar x:Name="PART_VerticalScrollBar" Grid.Row="0" Grid.Column="1"
					   Value="{TemplateBinding VerticalOffset}" Maximum="{TemplateBinding ScrollableHeight}"
                       ViewportSize="{TemplateBinding ViewportHeight}" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/>
            <ScrollBar x:Name="PART_HorizontalScrollBar" Orientation="Horizontal" Grid.Row="1" Grid.Column="0"
                       Value="{TemplateBinding HorizontalOffset}" Maximum="{TemplateBinding ScrollableWidth}"
                       ViewportSize="{TemplateBinding ViewportWidth}" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>
        </Grid>
    </ControlTemplate>

    <Style x:Key="GridViewColumnHeaderGripper" TargetType="Thumb">
        <Setter Property="Width" Value="18" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Border Padding="{TemplateBinding Padding}" Background="Transparent">
                        <Rectangle HorizontalAlignment="Center" Width="1">
                            <Rectangle.Fill>
                                <SolidColorBrush Color="{StaticResource Application_ListViewHeader_BorderBrush}" />
                            </Rectangle.Fill>
                        </Rectangle>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="BorderBrush">
            <Setter.Value>
                <LinearGradientBrush EndPoint="0.5,1"
                           StartPoint="0.5,0">
                    <GradientStop Color="Black"
                      Offset="0" />
                    <GradientStop Color="White"
                      Offset="1" />
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>
    </Style>

    <ControlTemplate x:Key="GridViewColumnHeaderTemplate" TargetType="GridViewColumnHeader">
        <Grid>
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup x:Name="CommonStates">
                	<VisualStateGroup.Transitions>
                		<VisualTransition From="Normal" GeneratedDuration="0:0:0.3" To="MouseOver"/>
                		<VisualTransition From="MouseOver" GeneratedDuration="0:0:0.4" To="Normal"/>
                		<VisualTransition From="MouseOver" GeneratedDuration="0:0:0.2" To="Pressed"/>
                		<VisualTransition From="Pressed" GeneratedDuration="0:0:0.2" To="MouseOver"/>
                	</VisualStateGroup.Transitions>
                    <VisualState x:Name="Normal" />
                    <VisualState x:Name="MouseOver">
                    	<Storyboard>
                    		<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="HeaderBorder">
                    			<EasingColorKeyFrame KeyTime="0" Value="{StaticResource Application_ListViewHeader_Background_Move}"/>
                    		</ColorAnimationUsingKeyFrames>
                    	</Storyboard>
                    </VisualState>
                    <VisualState x:Name="Pressed" >
                    	<Storyboard>
                    		<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="HeaderBorder">
                    			<EasingColorKeyFrame KeyTime="0" Value="{StaticResource Application_ListViewHeader_Background_Pressed}"/>
                    		</ColorAnimationUsingKeyFrames>
                    	</Storyboard>
                    </VisualState>
                    <VisualState x:Name="Disabled" >
                    	<Storyboard>
                    		<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="HeaderBorder">
                    			<EasingColorKeyFrame KeyTime="0" Value="{StaticResource Application_ListViewHeader_Background_Disabled}"/>
                    		</ColorAnimationUsingKeyFrames>
                    	</Storyboard>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
            <Border x:Name="HeaderBorder" BorderThickness="0,1,0,1" Padding="2,0,2,0">
                <Border.Background>
                    <SolidColorBrush Color="{StaticResource Application_ListViewHeader_Background}" />
                </Border.Background>
                <Border.BorderBrush>
                    <SolidColorBrush Color="{StaticResource Application_ListViewHeader_BorderBrush}"/>
                </Border.BorderBrush>
                <ContentPresenter x:Name="HeaderContent" Margin="0,0,0,1" RecognizesAccessKey="True" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
            </Border>
            <Thumb x:Name="PART_HeaderGripper" HorizontalAlignment="Right" Margin="0,0,-9,0" Style="{StaticResource GridViewColumnHeaderGripper}" />
        </Grid>
    </ControlTemplate>

    <ControlTemplate x:Key="PaddingGridViewColumnHeaderTemplate" TargetType="GridViewColumnHeader">
        <Border Name="HeaderBorder" BorderThickness="0,1,0,1">
            <Border.Background>
                <SolidColorBrush Color="{StaticResource Application_ListViewHeader_Background_Move}" />
            </Border.Background>
            <Border.BorderBrush>
                <SolidColorBrush Color="{StaticResource Application_ListViewHeader_BorderBrush}"/>
            </Border.BorderBrush>
        </Border>
    </ControlTemplate>

    <ControlTemplate x:Key="ListViewTemplate" TargetType="ListView">
        <Border Name="Border" BorderThickness="1">
            <Border.Background>
                <SolidColorBrush Color="{StaticResource Application_ListView_Background}" />
            </Border.Background>
            <Border.BorderBrush>
                <SolidColorBrush Color="{StaticResource Application_ListView_BorderBrush}"/>
            </Border.BorderBrush>
            <ScrollViewer Style="{DynamicResource {x:Static GridView.GridViewScrollViewerStyleKey}}">
                <ItemsPresenter />
            </ScrollViewer>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsGrouping" Value="true">
                <Setter Property="ScrollViewer.CanContentScroll" Value="false" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
</ResourceDictionary>